<h3>Step 1: Determine the look back periods</h3>

<p>
  The lookback period is the number of bars back from the most recent bar that the price or indicator looks at to make the momentum calculations.
  To start the look back period is set to 20 days to determine its buy and sell levels. We change the number of look back days in proportion to changes in market volatility. Through this method the number of look back days changes on a daily basis. At the end of each day, the current market volatility is calculated by the standard deviation of the past 30 day's closing prices.
</p>
<div class="section-example-container">

<pre class="python">close = self.History(self.syl, 31, Resolution.Daily)['close']
   todayvol = np.std(close[1:self.numdays+1])
   yesterdayvol = np.std(close[0:self.numdays])
   deltavol = (todayvol - yesterdayvol) / todayvol
   self.numdays = round(self.numdays * (1 + deltavol)) # the number of days must be integer
 </pre>
 </div>

<p>
  Though the look back days are dynamic, it needs to be restricted within an acceptable range of 20 to 60.
</p>

<h3>Step 2: Choose the algorithm buy/sell point</h3>

<p>
  For a buy setup, the close price of the previous day must be above the upper Bollinger Band. In addition the ask price must be above the highest high of the most recent N days. Where N is the look back days from Step-1.
  For a sell setup, the close price of previous day must be below the lower Bollinger Band and the ask price must be below the lowest low of the most recent N days. The length of the Bollinger Band calculation is the same number of look back days that is generated by Step-1.
</p>
<p>
  Bollinger Band is a popular technical indicator. k is a constant. Here we choose k=2.
</p>
\[ Upper Band = moving\ average + k\times standard\  deviation \]

\[ Lower Band = moving\ average - k\times standard\  deviation \]
<p>
  QuantConnect provides more than 100 technical indicators for you to use in your algorithm. These are provided as class objects in Python. A full list of the indicators and their properties can be found in the reference table of <a href="https://www.quantconnect.com/docs#Indicators">the documentation page</a>.
</p>
<div class="section-example-container">

<pre class="python">self.bolband = self.BB(self.syl,self.numdays,decimal.Decimal(2),MovingAverageType.Exponential,Resolution.Daily)
     self.upband = self.bolband.UpperBand
     self.lowband = self.bolband.LowerBand
</pre>
</div>

<h3>Step 3: Choose the algorithm liquidation point</h3>
<p>
  The exit signal for an existing holding is determined by calculating a simple moving average of closing prices for the past look back days. That is to say, we liquidate a long position if the current price is lower than the moving average of the close price over the look back period, and vice versa for selling a short position.
</p>
<div class="section-example-container">

<pre class="python">self.buypoint = max(self.high)
self.sellpoint = min(self.low)
historyclose = self.History(self.syl, self.numdays, Resolution.Daily)['close']
self.longLiqPoint = np.mean(historyclose)
self.shortLiqPoint = np.mean(historyclose)
self.yesterdayclose = historyclose.iloc[-1]
</pre>
</div>
